import { defineStore } from "pinia";
import {reqIntegrated,reqPropertiesFilter,reqPopTraining, reqNewcomer, reqLastest, reqRecommend} from '@/api/resource/resource'
import type {videoListContentType,ChoisesContentType} from '@/api/resource/resourceType'
import { ElLoading } from 'element-plus';
interface stateType {
    ChoisesList: ChoisesContentType[];
    videoList:videoListContentType[]
  }

export const useResourceStore = defineStore('resourse',{
state:():stateType=>{
    return{
        ChoisesList:[],
        videoList:[]
    }
},
actions:{

    // 请求推荐视频列表
    async getRecommend(pageNum:number,pageSize:number){
        try {
            const result  = await reqRecommend(pageNum,pageSize)
            this.videoList = result.content
        } catch (error) {
            return Promise.reject(error)
        }
    },



    // 获取可隐藏的动态条件
    async getPropertiesFilter(){
        try {
            const result = await reqPropertiesFilter()
            console.log(result);
            this.ChoisesList = result.content
        } catch (error) {
            return Promise.reject(error)
        }
    },

    // 多条件过滤
    async getLastest(pageNum:number,pageSize:number,filterInfo:any){
        try {
            ElLoading.service({ fullscreen: true });
            const result = await reqLastest(pageNum,pageSize,filterInfo)
            ElLoading.service({ fullscreen: true }).close();
            this.videoList = result.content
        } catch (error) {
            return Promise.reject(error)
        }
    },


    // 请求综合榜单
    async getIntegrated(pageNum:number,pageSize:number){
        try {
            const result = await reqIntegrated(pageNum,pageSize)
            console.log(result);
            this.videoList = result.content
        } catch (error) {
            return Promise.reject(error)
        }
    },

    // 请求热练榜
    async getPopTraining(pageNum:number,pageSize:number){
        try {
            const result = await reqPopTraining(pageNum,pageSize)
            console.log(result);
            this.videoList = result.content
        } catch (error) {
            return Promise.reject(error)
        }
    },

    // 请求新锐榜单/最新
    async getNewcomer(pageNum:number,pageSize:number){
        try {
            const result = await reqNewcomer(pageNum,pageSize)
            console.log(result);
            this.videoList = result.content

        } catch (error) {
            return Promise.reject(error)
        }
    }
}


   

})